﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.IO;
using ElectronicWMSA.Comm.ClassFiles;

namespace EWMSA_KANBAN
{
    public partial class KANBAN_Frm : Form
    {
        public KANBAN_Frm()
        {
            InitializeComponent();
        }
        public int id = 0;
        public int Start_Form1 = 0;
        private void Form1_Load(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Maximized;
            this.tabControl1.SelectedIndex = 0;
            this.GetSytemConfig();
            this.GET();
        }

        #region GetSytemConfig
        private void GetSytemConfig()
        {
            if (File.Exists("SytemConfig.xml"))
            {
                string APPLICATIONPROGRAMIP = "";
                string APPLICATIONPROGRAMDB = "";
                string APPLICATIONPROGRAMUR = "";
                string APPLICATIONPROGRAMPD = "";

                string SAPIP = "";
                string SAPDB = "";
                string SAPUR = "";
                string SAPPD = "";
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.Load("SytemConfig.xml");
                foreach (XmlNode item in xmldoc.GetElementsByTagName("DOC"))
                {
                    foreach (XmlNode items in item.ChildNodes)
                    {
                        if (items.Name == "SYSTEMNAME")
                            EWMSAClass.SYSTEMNAME = items.InnerText.Trim();
                        else if (items.Name == "NUMBER")
                            EWMSAClass.WMS_Number = items.InnerText.Trim();
                        else if (items.Name == "CUSTOMERNAME")
                            EWMSAClass.CUSTOMERNAME = items.InnerText.Trim();
                        else if (items.Name == "VERSION")
                            EWMSAClass.VERSION = items.InnerText.Trim();
                        else if (items.Name == "APPLICATIONPROGRAMIP")
                        {
                            APPLICATIONPROGRAMIP = items.InnerText.Trim();
                            WMSADBUtility.Database.ServerAddress = APPLICATIONPROGRAMIP;
                        }
                        else if (items.Name == "APPLICATIONPROGRAMDB")
                        {
                            APPLICATIONPROGRAMDB = items.InnerText.Trim();
                            WMSADBUtility.Database.DBName = "WMSA17DB";
                        }
                        else if (items.Name == "APPLICATIONPROGRAMUR")
                        {
                            APPLICATIONPROGRAMUR = items.InnerText.Trim();
                        }
                        else if (items.Name == "APPLICATIONPROGRAMPD")
                        {
                            if (items.InnerText.Trim() != "")
                                APPLICATIONPROGRAMPD = ElectronicWMSA.Comm.ClassFiles.PCInfoClass.Decryption(items.InnerText.Trim(), "/*-./.,@");
                        }

                        else if (items.Name == "SAPIP")
                            SAPIP = items.InnerText.Trim();
                        else if (items.Name == "SAPDB")
                            SAPDB = items.InnerText.Trim();
                        else if (items.Name == "SAPUSER")
                            SAPUR = items.InnerText.Trim();
                        else if (items.Name == "SAPPWD")
                        {
                            if (items.InnerText.Trim() != "")
                                SAPPD = ElectronicWMSA.Comm.ClassFiles.PCInfoClass.Decryption(items.InnerText.Trim(), "/*-./.,@");
                        }
                    }
                }
                WMSADBUtility.Database.ConnString = "server=" + APPLICATIONPROGRAMIP + ";database=" + APPLICATIONPROGRAMDB + ";uid=" + APPLICATIONPROGRAMUR + ";pwd=" + APPLICATIONPROGRAMPD + ";";
                WMSADBUtility.DbHelperSAP.connectionString = "server=" + SAPIP + ";database=" + SAPDB + ";uid=" + SAPUR + ";pwd=" + SAPPD + ";";
            }
        }
        #endregion

        public void GET()
        {
            New_Frm1();
            New_Frm2();
            New_Frm3();
            New_Frm4();
            New_Frm5();
            New_Frm6();
        }

        //拣货路线
        private void New_Frm1()
        {
            ElectronicWMSA.Warehouse.Warehouse_OrderPickingRouteFrm f = new ElectronicWMSA.Warehouse.Warehouse_OrderPickingRouteFrm();
            f.TopLevel = false;
            f.Dock = DockStyle.Fill;
            f.Show();
            tabPage2.Controls.Add(f);
        }

        /// <summary>
        /// 成品定位
        /// </summary>
        private void New_Frm2()
        {
            ElectronicWMSA.Warehouse.Warehouse_PartsLocationFrm f2 = new ElectronicWMSA.Warehouse.Warehouse_PartsLocationFrm();
            f2.TopLevel = false;
            f2.Dock = DockStyle.Fill;
            f2.Show();
            tabPage3.Controls.Add(f2);
        }

        /// <summary>
        /// 拣货进度
        /// </summary>
        private void New_Frm6()
        {
            ElectronicWMSA.Warehouse.List_PickingFrm1 f1 = new ElectronicWMSA.Warehouse.List_PickingFrm1();
            f1.TopLevel = false;
            f1.Dock = DockStyle.Fill;
            f1.Show();
            tabPage4.Controls.Add(f1);
        }

        /// <summary>
        /// 入库报表
        /// </summary>
        private void New_Frm3()
        {
            ElectronicWMSA.Warehouse.List_StockRuGoingReportFrm f2 = new ElectronicWMSA.Warehouse.List_StockRuGoingReportFrm();
            f2.TopLevel = false;
            f2.Dock = DockStyle.Fill;
            f2.Show();
            tabPage5.Controls.Add(f2);
        }

        /// <summary>
        /// 出库报表
        /// </summary>
        private void New_Frm4()
        {
            ElectronicWMSA.Warehouse.List_StockOutGoingReportFrm f3 = new ElectronicWMSA.Warehouse.List_StockOutGoingReportFrm();
            f3.TopLevel = false;
            f3.Dock = DockStyle.Fill;
            f3.Show();
            tabPage6.Controls.Add(f3);
        }

        /// <summary>
        /// 库龄分析
        /// </summary>
        private void New_Frm5()
        {
            ElectronicWMSA.Warehouse.Frm_OldLibra f2 = new ElectronicWMSA.Warehouse.Frm_OldLibra();
            f2.TopLevel = false;
            f2.Dock = DockStyle.Fill;
            f2.Show();
            tabPage7.Controls.Add(f2);
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            QieHuan();
        }
        public void QieHuan()
        {
            if (Start_Form1 == 0)
            {
                id++;
                Start_Form1++;
            }

            tabControl1.SelectedIndex = id;

            switch (id)
            {

                case 0: tabControl1.SelectedIndex = id; id++;
                    break;
                case 1: tabControl1.SelectedIndex = id; id++;
                    break;
                case 2: tabControl1.SelectedIndex = id; id++;
                    break;
                case 3: tabControl1.SelectedIndex = id; id++;
                    break;
                case 4: tabControl1.SelectedIndex = id; id++;
                    break;
                case 5: tabControl1.SelectedIndex = id; id++;
                    break;
                case 6: tabControl1.SelectedIndex = id; id = 0;
                    break;

            }
        }
    }
}
